﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using DACNPM.MyUserControl.UCHienThi;
using DACNPM.MyUserControl.UCMenu;

using DACNPM;

namespace DACNPM
{
    public partial class FormHome : Form
    {
        UserBUO userbuo = new UserBUO();
        String idnhanvien;

        public FormHome()
        {
            InitializeComponent();
        }
        
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            try
            {
                idnhanvien = userbuo.GetSingle(txtUsername.Text).id_NhanVien;
                UCHome uchome = new UCHome(idnhanvien);
                UCDanhSachChucNang ucds = new UCDanhSachChucNang(idnhanvien);
                if (userbuo.CheckUser(txtUsername.Text, txtPassword.Text))
                {
                    MessageBox.Show(userbuo.GetSingle(txtUsername.Text).userName.ToString().Trim());
                    grbMenu.Controls.Clear();
                    grbMenu.Controls.Add(uchome);
                    grbHienThiChucNang.Controls.Clear();
                    grbHienThiChucNang.Controls.Add(ucds);

                    //hiển thị các nút
                    btnNhanSu.Enabled = true;
                    btnKhachHang.Enabled = true;
                    btnDonDatHang.Enabled = true;
                    btnBanHang.Enabled = true;
                    btnNCC.Enabled = true;
                    btnThongKe.Enabled = true;
                    btnNhapHang.Enabled = true;
                    btnBanHang.Enabled = true;
                    btnHangHoa.Enabled = true;
                    btnBackupRestore.Enabled = true;

                    //NguoiDung.userName = userbuo.GetSingle(txtUsername.Text).userName.ToString().Trim();
                    //NguoiDung.idNhanVen = userbuo.GetSingle(txtUsername.Text).id_NhanVien.ToString().Trim();


                }
                else
                {
                    lblThongBao.Text = "Sai username hoặc passwowrd";
                }
            }
            catch (Exception)
            {

                lblThongBao.Text = "Sai username hoặc passwowrd";
            }
            
            

        }

        private void button1_Click(object sender, EventArgs e)
        {
            UCDanhSachNV ucDSNV = new UCDanhSachNV();
            UCChucNangNhanVien ucCNNV = new UCChucNangNhanVien(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSNV);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNNV);
        }

        private void btnKhachHang_Click(object sender, EventArgs e)
        {
            UCDanhSachKH ucDSKH = new UCDanhSachKH();
            UCChucNangKhachHang ucCNKH = new UCChucNangKhachHang(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSKH);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNKH);
        }

        private void btnHangHoa_Click(object sender, EventArgs e)
        {
            UCDanhSachHang ucDSHang = new UCDanhSachHang();
            UCChucNangHangHoa ucCNHang = new UCChucNangHangHoa(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSHang);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNHang);
        }

        private void btnDonDatHang_Click(object sender, EventArgs e)
        {
            UCDanhSachDDH ucDSDDH = new UCDanhSachDDH(idnhanvien);
            UCChucNangDDH ucCNDDH = new UCChucNangDDH(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSDDH);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNDDH);
        }

        private void btnBanHang_Click(object sender, EventArgs e)
        {
            UCDanhSachHoaDonBan ucDSHDB = new UCDanhSachHoaDonBan(idnhanvien);
            UCChucNangHoaDonBan ucCNHDB = new UCChucNangHoaDonBan(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSHDB);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNHDB);
        }

        private void btnNhapHang_Click(object sender, EventArgs e)
        {
            UCDanhSachHoaDonNhapHang ucDSHDN = new UCDanhSachHoaDonNhapHang(idnhanvien);
            UCChucNangHDNhap ucCNHDN = new UCChucNangHDNhap(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSHDN);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNHDN);
        }

        private void btnNCC_Click(object sender, EventArgs e)
        {
            UCDanhSachNCC ucDSNCC = new UCDanhSachNCC();
            UCChucNangNCC ucCNNCC = new UCChucNangNCC(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucDSNCC);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNNCC);
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    idnhanvien = userbuo.GetSingle(txtUsername.Text).id_NhanVien;
                    UCHome uchome = new UCHome(idnhanvien);
                    UCDanhSachChucNang ucds = new UCDanhSachChucNang(idnhanvien);
                    //UserBUO userbuo = new UserBUO();
                    //UCHome uchome = new UCHome(idnhanvien);
                    //UCDanhSachChucNang ucds = new UCDanhSachChucNang(idnhanvien);
                    if (userbuo.CheckUser(txtUsername.Text, txtPassword.Text))
                    {
                        grbMenu.Controls.Clear();
                        grbMenu.Controls.Add(uchome);
                        grbHienThiChucNang.Controls.Clear();
                        grbHienThiChucNang.Controls.Add(ucds);

                        //hiển thị các nút
                        btnNhanSu.Enabled = true;
                        btnKhachHang.Enabled = true;
                        btnDonDatHang.Enabled = true;
                        btnBanHang.Enabled = true;
                        btnNCC.Enabled = true;
                        btnThongKe.Enabled = true;
                        btnNhapHang.Enabled = true;
                        btnBanHang.Enabled = true;
                        btnHangHoa.Enabled = true;
                        btnBackupRestore.Enabled = true;
                        btnHome.Enabled = true;

                    }
                    else
                    {

                    }
                }
            }
            catch (Exception)
            {

                lblThongBao.Text = "Sai username hoặc passwowrd";
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            
            
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            UCHome ucHome = new UCHome(idnhanvien);
            UCDanhSachChucNang ucds = new UCDanhSachChucNang(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucds);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucHome);
        }

        private void txtUsername_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    idnhanvien = userbuo.GetSingle(txtUsername.Text).id_NhanVien;
                    UCHome uchome = new UCHome(idnhanvien);
                    UCDanhSachChucNang ucds = new UCDanhSachChucNang(idnhanvien);
                    //UserBUO userbuo = new UserBUO();
                    //UCHome uchome = new UCHome(idnhanvien);
                    //UCDanhSachChucNang ucds = new UCDanhSachChucNang(idnhanvien);
                    if (userbuo.CheckUser(txtUsername.Text, txtPassword.Text))
                    {
                        grbMenu.Controls.Clear();
                        grbMenu.Controls.Add(uchome);
                        grbHienThiChucNang.Controls.Clear();
                        grbHienThiChucNang.Controls.Add(ucds);

                        //hiển thị các nút
                        btnNhanSu.Enabled = true;
                        btnKhachHang.Enabled = true;
                        btnDonDatHang.Enabled = true;
                        btnBanHang.Enabled = true;
                        btnNCC.Enabled = true;
                        btnThongKe.Enabled = true;
                        btnNhapHang.Enabled = true;
                        btnBanHang.Enabled = true;
                        btnHangHoa.Enabled = true;
                        btnBackupRestore.Enabled = true;
                        btnHome.Enabled = true;

                    }
                    else
                    {
                        
                    }
                }
            }
            catch (Exception)
            {

                lblThongBao.Text = "Sai username hoặc passwowrd";
            }
            
        }

        private void btnThongKe_Click(object sender, EventArgs e)
        {
            UCChucNangThongKe ucCNTK = new UCChucNangThongKe(idnhanvien);
            UCThongKeDoanhThu ucTKDT = new UCThongKeDoanhThu();

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucTKDT);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucCNTK);
        }

        private void btnBackupRestore_Click(object sender, EventArgs e)
        {
            BackupRestore ucBR = new BackupRestore();
            UCHome ucHome = new UCHome(idnhanvien);

            Form form = this.ParentForm;

            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ucBR);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(ucHome);
        }
    }
}
